<#escape x as (x)!"">

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{
            day: null,
            timeChecked: false,
            startTime: null,
            endTime: null,
            errorChecked: false,
            dateType:'1',
            groupDateChecked:false,
            groupDateRadio: '1',
            groupSpChecked:false,
            groupProvinceChecked:false,
            groupErrorCodeChecked:false,
            criterias:[{opt:"and",del:false,optList:[{checked:false,opt:"and",del:false,column:null,operator:1,
            value:null}]}]
        },
        pickerOptions1: {
            shortcuts: [
                {
                    text: '今天(00:00:00)',
                    onClick: function (picker) {
                        const date = new Date();

                        const h = date.getHours();
                        const m = date.getMinutes();
                        const s = date.getSeconds();
                        const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                            * 1000 + date.getMilliseconds();

                        date.setTime(date.getTime() - ms);
                        picker.$emit('pick', date);
                    }
                },
                {
                    text: '今天(23:59:59)',
                    onClick: function (picker) {
                        const date = new Date();

                        const h = date.getHours();
                        const m = date.getMinutes();
                        const s = date.getSeconds();
                        const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                            * 1000 + date.getMilliseconds();

                        const ms235959 = 3600 * 1000 * 24 - 1000;

                        date.setTime(date.getTime() - ms + ms235959);
                        picker.$emit('pick', date);
                    }
                },
                {
                    text: '昨天(00:00:00)',
                    onClick: function (picker) {
                        const date = new Date();
                        const h = date.getHours();
                        const m = date.getMinutes();
                        const s = date.getSeconds();
                        const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                            * 1000 + date.getMilliseconds();
                        date.setTime(date.getTime() - 3600 * 1000 * 24
                            - ms);
                        picker.$emit('pick', date);
                    }
                },
                {
                    text: '昨天(23:59:59)',
                    onClick: function (picker) {
                        const date = new Date();
                        const h = date.getHours();
                        const m = date.getMinutes();
                        const s = date.getSeconds();
                        const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                            * 1000 + date.getMilliseconds();

                        const ms235959 = 3600 * 1000 * 24 - 1000;

                        date.setTime(date.getTime() - 3600 * 1000 * 24
                            - ms + ms235959);
                        picker.$emit('pick', date);
                    }
                },
                {
                    text: '一周前',
                    onClick: function (picker) {
                        const date = new Date();
                        const h = date.getHours();
                        const m = date.getMinutes();
                        const s = date.getSeconds();
                        const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                            * 1000 + date.getMilliseconds();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7
                            - ms);
                        picker.$emit('pick', date);
                    }
                }]
        },
        showSql:false,
        sql:'',
		showList: true,
		dataList:[],
        total: 0 ,
        columnsList: [
          <#if columns??>
              <#list columns as column>
                <#if !column.nolist>
          {name: '${column.shortComments}', field: '${column.attrname}' , isShow: true},
                </#if>
              </#list>
          </#if>
        ],
	<#if columns??>
		<#list columns as column>
		<#if column.map??>
        ${column.attrname}List: [
        <#list column.map?keys as key> 
          {'value': ${key}, 'text': '${column.map[key]}'}<#if key_has_next>,</#if>
        </#list>
        ],
        ${column.attrname}Map: {},
        ${column.attrname}SearchList: {},
		</#if>
		</#list>
	</#if>
		selectList : [ {
            'value' : 'a.destNumber',
            'text' : '目的号码'
        }, {
            'value' : 'a.ErrorCode',
            'text' : '错误码'
        }, {
            'value' : 'a.srcNumber',
            'text' : '源号码'
        } , {
            'value' : 'a.SPNUMBER',
            'text' : 'SP企业代码'
        }  ],
        operatorList : [ {
            'value' : '1',
            'text' : '等于(=)'
        }, {
            'value' : '2',
            'text' : '不等于(<>)'
        }, {
            'value' : '3',
            'text' : '小于(<)'
        } , {
            'value' : '4',
            'text' : '大于(>)'
        }, {
            'value' : '5',
            'text' : '大于等于(>=)'
        } , {
            'value' : '6',
            'text' : '小于等于(<=)'
        }, {
            'value' : '7',
            'text' : '子串'
        }, {
            'value' : '8',
            'text' : '为空'
        }       ],
        optList : [ {
            'value' : 'and',
            'text' : 'And'
        }, {
            'value' : 'or',
            'text' : 'Or'
        }]
	},
    mounted: function () {
        toastr.options = {
            closeButton : true,
            debug : false,
            progressBar : false,
            positionClass : "toast-top-center",
            onclick : null,
            showDuration : "300",
            hideDuration : "1000",
            timeOut : "2000",
            extendedTimeOut : "1000",
            showEasing : "swing",
            hideEasing : "linear",
            showMethod : "fadeIn",
            hideMethod : "fadeOut"
        };
    	<#if columns??>
    		<#list columns as column>
    		<#if column.map??>
        this.${column.attrname}Map = list2Map(this.${column.attrname}List)
    		</#if>
    		</#list>
    	</#if>
        this.initDate();
    },
	methods: {
        initDate: function () {
            const date = new Date();

            const h = date.getHours();
            const m = date.getMinutes();
            const s = date.getSeconds();
            const ms = h * 3600 * 1000 + m * 60 * 1000 + s
                * 1000 + date.getMilliseconds();

            date.setTime(date.getTime() - ms);

            this.q.startTime = DateFormat(date, 'yyyy-MM-dd hh:mm:ss');

            const ms24 = 24 * 3600 * 1000 - 1000;
            date.setTime(date.getTime() + ms24);

            this.q.endTime = DateFormat(date, 'yyyy-MM-dd hh:mm:ss');
        },
		query: function () {
		    if(vm.q.day == null)
            {
               // toastr.error("日期不能为空!");
               // return;
            }
			vm.reload();
		},
		addItem: function (item) {
            item.optList.push({opt:"and",del:false,optList:[{checked:false,opt:"and",del:false,column:null,
            operator:1,value:null}]});
        },
        addAnd: function () {
            vm.q.criterias.push({opt:"and",del:false,optList:[{checked:false,opt:"and",del:false,column:null,
            operator:1,value:null}]});
        },
        addOr: function () {
            vm.q.criterias.push({opt:"or",del:false,optList:[{checked:false,opt:"and",del:false,column:null,
            operator:1,value:null}]});
        },
        sqlHide:function () {
            vm.showSql = false;
        },
        getSql: function () {
            if(vm.q.day == null)
            {
               // toastr.error("日期不能为空!");
               // return;
            }
            vm.sql= "";
            $.ajax({
                type: "POST",
                url: "../${pathName}/tosql",
                data: JSON.stringify(vm.q),
                success: function (r) {
                    if (r.code == 0) {
                        vm.showSql = true;
                        vm.sql=r.data;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        changeSelect: function (opt) {
            opt.value = null;
        },
		getInfo: function(${pk.attrname}){
			$.get("../${pathName}/info/"+${pk.attrname}, function(r){
                vm.${classname} = r.data;
            });
		},
        handleCommand:function (commond) {
            if(commond=='d')
            {
                location.href = "../${pathName}/download?query=" + escape(JSON.stringify(vm.q));
                return;
            }

            if(vm.total>5000)
            {
                toastr.error("导出数据条数不能超过5000条,请用sql从数据库导出!");
                return;
            }

            if(commond=='a')
            {
                $("#data").tableExport({type:'csv'},'data');
                return;
            }

            if(commond=='b')
            {
                $("#data").tableExport({type:'txt'},'data');
                return;
            }

            if(commond=='c')
            {
                $("#data").tableExport({type:'excel',escape:false,
                    mso: {fileFormat:'xlsx',
                        excelstyles: ['border-bottom', 'border-top', 'border-left', 'border-right'],
                        worksheetName: ['Data']}},'data');
                return;
            }
        },
        exportExl: function () {
            if(vm.total>5000)
            {
                toastr.error("导出数据条数不能超过5000条,请用sql从数据库导出!");
                return;
            }

            if(vm.total>5000)
            {
                toastr.error("导出数据条数不能超过5000条,请用sql从数据库导出!");
                return;
            }

            $("#data").tableExport({type:'excel',escape:false,
                mso: {fileFormat:'xlsx',
                    excelstyles: ['border-bottom', 'border-top', 'border-left', 'border-right'],
                    worksheetName: ['Data']}},'data');

        },
		reload: function (event) {
			vm.showList = true;
            $.ajax({
                type: "POST",
                url: "../${pathName}/list",
                data: JSON.stringify(vm.q),
                success: function (r) {
                    if (r.code == 0) {
                        vm.dataList = r.data.list;
                        vm.total = r.data.totalCount;

                    } else {
                        toastr.error(r.msg);
                    }
                }
            });
		}
	}
});
</#escape>